// pages/month_results_zg/month_results_zg.js
var util = require('../../utils/util');
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}

Page({

    /**
     * 页面的初始数据
     */
    data: {
        membership_id: '',
        prev_time: '',
        order_list: [],
        order_price: '',
        member_list: [],
        array: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var This = this;
        var time = util.formatTime(new Date());
        var date_value = time.slice(0, 4) + "-" + time.slice(5, 7)
        This.setData({
            membership_id: wx.getStorageSync('membership_id'),
            prev_time: date_value,
            level: wx.getStorageSync('level')
        })
        This.loading();
    },
    loading() {
        var This = this;
        App._get('coach/member/get_coach_achievement', {
            phone: wx.getStorageSync('phone'),
            openid: wx.getStorageSync('openid'),
            store_id: wx.getStorageSync('store_id'),
            // phone: 18810450512,
            // openid: 1,
            // store_id: 53,
            date_str: This.data.prev_time
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    order_price: res.achievement_money,
                    order_list: res.achievement_data
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    bindDatesChange(e) {
        var This = this;
        This.setData({
            order_list: [],
            prev_time: e.detail.value
        })
        This.loading();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})